package service;

import java.sql.SQLException;
import java.util.List;

import dao.NoticeDao;
import entity.Notice;
public class NoticeService {
	private NoticeDao dao = new NoticeDao();
	//前台系统，查询最新添加或修改的一条公告
	public Notice getRecentNotice() {
		try {
			return dao.getRecentNotice();
		} catch (SQLException e) {
			throw new RuntimeException("查询最新添加或修改的一条公告失败！");
		}
	}
	/*
	 * 后台添加公告
	 */
	public void addNotice(Notice bean) {
		// TODO Auto-generated method stub
		try {
			dao.addNotice(bean);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException("添加公告失败!");
		}
		
	}
	/*
	 * 后台删除公告
	 */
	public void deleteNotice(String n_id) {
		// TODO Auto-generated method stub
		try {
			dao.deleteNotice(n_id);
		} catch (SQLException e) {
			throw new RuntimeException("根据id删除公告失败！");
		}
		
	}
	/*
	 * 后台修改公告
	 */
	public void updateNotice(Notice n) {
		// TODO Auto-generated method stub
		try {
			dao.updateNotice(n);
		} catch (SQLException e) {
			throw new RuntimeException("根据id修改公告失败！");
			
		}
		
	}
	/*
	 * 后台查询所有公告
	 */
	public List<Notice> getAllNotices() {
		// TODO Auto-generated method stub
		try {
			return dao.getAllNotices();
		} catch (SQLException e) {
			throw new RuntimeException("查询所有的公告失败！");
		}
		
	}
	/*
	 * 后台根据id查询公告
	 */
	public Notice findNoticeById(String n_id) {
		// TODO Auto-generated method stub
		try {
			return dao.findNoticeById(n_id);
		} catch (SQLException e) {
			throw new RuntimeException("查询公告失败！");
		}
	}
}
